package com.zwl.smartplatform.utils;

import com.zwl.smartplatform.pojo.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.HashMap;
import java.util.Map;

public class SecurityUtils {

    public static Map<Thread, Object> map = new HashMap<>();

    public static User getUser() {
        //内部使用的是ThreadLocal,在相同的线程的不通的类之间共享数据,ThreadLocal相当于一个map, key是当前线程对象
        User user = (User) ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
                .getSession().getAttribute("user");
        return user;
    }
}
